<template>
  <el-row class="bottom-line">
    <div class="subtitle">
      确认收款银行信息
    </div>
    <el-row class="flex-box confirm" type="flex" justify="space-between" align="top">
      <el-col :lg="11" :md="11" :sm="24">
        <!--<el-card>-->
        <v-form
          :form-title="receiptBankTitle"
          :form-data="receiptBankData"
          @change="change"
        />
        <!--</el-card>-->
      </el-col>
    </el-row>
  </el-row>
</template>

<script>
export default {
  name: 'ReceiptBank',
  props: {
    totalMoney: {
      type: Number,
      default: 0
    },
    receiptBankData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      // 收款银行信息
      receiptBankList: [],
      receiptBankTitle2: [
        {
          cn: '收款账号',
          en: 'accounts',
          disabled: true
        },
        {
          cn: '开户行',
          en: 'openbank',
          disabled: true
        },
        {
          cn: '收款金额',
          en: 'money'
          // disabled: true
        },
        {
          cn: '备注',
          en: 'notes',
          type: 'textarea'
          // disabled: true
        }
      ]
    }
  },
  computed: {
    receiptBankTitle() {
      return this.receiptBankTitle1.concat(this.receiptBankTitle2)
    },
    receiptBankTitle1() {
      return ([
        {
          cn: '收款账户',
          en: 'name',
          type: 'select',
          list: this.receiptBankList
        }
      ])
    }
  },
  watch: {
    totalMoney(val) {
      console.log(val, 'receipt')
      this.$set(this.receiptBankData, 'money', val)
    }
  },
  created() {
    this.getReceiptBankList()
  },
  methods: {
    change(val) {
      console.log(val)
      let data
      this.receiptBankList.forEach((item) => {
        if (item.value === val) {
          data = item.full
          this.receiptBankData.accounts = data.accounts
          this.receiptBankData.openbank = data.openbank
        }
      })
      this.$emit('selectChange', data)
    },
    // 获取收款银行信息列表
    getReceiptBankList() {
      this.$get('action/ReceivBank/dataGrid')
        .then(res => {
          this.$set(this.receiptBankTitle1, 0, {})
          this.receiptBankList = res.data.list.map(item => {
            const obj = {}
            obj.label = item.name
            obj.value = item.id
            obj.full = item
            return obj
          })
        })
    }
  }
}
</script>

<style scoped>

</style>
